package com.lch.thread.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 *
 * @author: liuchenhui
 * @create: 2019-05-26 17:50
 **/
public class FutureDemo implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println("execute:call");
        Thread.sleep(5000L);
        return "结束执行,返回结果";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureDemo futureDemo = new FutureDemo();
        FutureTask<String> futureTask = new FutureTask<>(futureDemo);

        new Thread(futureTask).start();

        System.out.println(futureTask.get());// 阻塞获取结果
    }
}
